package com.zzjc.web.controller;

import com.zzjc.web.entity.SwimmingRoom;
import com.zzjc.web.service.SwimmingRoomService;
import com.zzjc.web.util.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(tags = "泳馆管理接口")
@RestController
@RequestMapping("/swimmingRoom")
public class SwimmingRoomController {

    @Autowired
    private SwimmingRoomService swimmingRoomService;

    @ApiOperation("添加游泳场所信息")
    @PostMapping("/addRoom")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomName", value = "场所名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "phone", value = "联系电话", required = false, dataType = "String"),
            @ApiImplicitParam(name = "province", value = "省份", required = false, dataType = "String"),
            @ApiImplicitParam(name = "city", value = "城市", required = false, dataType = "String"),
            @ApiImplicitParam(name = "address", value = "详细地址", required = false, dataType = "String"),
            @ApiImplicitParam(name = "notes", value = "备注", required = false, dataType = "String")
    })
    public ApiResponse<?> addRoom(
            @RequestParam(value = "roomName", required = true) String roomName,
            @RequestParam(value = "phone", required = false) String phone,
            @RequestParam(value = "province", required = false) String province,
            @RequestParam(value = "city", required = false) String city,
            @RequestParam(value = "address", required = false) String address,
            @RequestParam(value = "notes", required = false) String notes) {
        SwimmingRoom room = new SwimmingRoom();
        room.setRoomName(roomName);
        room.setPhone(phone);
        room.setProvince(province);
        room.setCity(city);
        room.setAddress(address);
        room.setNotes(notes);
        room.setStatus(1);
        return swimmingRoomService.addRoom(room);
    }

    @ApiOperation("更新游泳场所信息")
    @PostMapping("/updateRoom")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomId", value = "场所id", required = true, dataType = "Int"),
            @ApiImplicitParam(name = "roomName", value = "场所名称", required = false, dataType = "String"),
            @ApiImplicitParam(name = "phone", value = "联系电话", required = false, dataType = "String"),
            @ApiImplicitParam(name = "province", value = "省份", required = false, dataType = "String"),
            @ApiImplicitParam(name = "city", value = "城市", required = false, dataType = "String"),
            @ApiImplicitParam(name = "address", value = "详细地址", required = false, dataType = "String"),
            @ApiImplicitParam(name = "notes", value = "备注", required = false, dataType = "String"),
    })
    public ApiResponse<?> updateRoom(
            @RequestParam(value = "roomId", required = true) Integer roomId,
            @RequestParam(value = "roomName", required = false) String roomName,
            @RequestParam(value = "phone", required = false) String phone,
            @RequestParam(value = "province", required = false) String province,
            @RequestParam(value = "city", required = false) String city,
            @RequestParam(value = "address", required = false) String address,
            @RequestParam(value = "notes", required = false) String notes) {
        SwimmingRoom room = new SwimmingRoom();
        room.setRoomId(roomId);
        room.setRoomName(roomName);
        room.setPhone(phone);
        room.setProvince(province);
        room.setCity(city);
        room.setAddress(address);
        room.setNotes(notes);
        return swimmingRoomService.updateRoom(room);
    }

    @ApiOperation("删除游泳场所")
    @PostMapping("/deleteRoom")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomList", value = "游泳场所id集合", dataType = "String", required = true)
    })
    public ApiResponse deleteRoom(
            @RequestParam(value = "roomList", required = true) List<Integer> roomList) {
        return swimmingRoomService.deleteRoom(roomList);
    }

    @ApiOperation("获取游泳场所列表")
    @PostMapping("/listRoom")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomId", value = "场所id", dataType = "Integer", required = false),
            @ApiImplicitParam(name = "roomName", value = "场所名称", dataType = "String", required = false),
            @ApiImplicitParam(name = "pageNum", value = "当前页index", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页面数据条数", dataType = "Integer", required = true)
    })
    public ApiResponse getAllRooms(
            @RequestParam(value = "roomId", required = false) Integer roomId,
            @RequestParam(value = "roomName", required = false) String roomName,
            @RequestParam(value = "pageNum", required = true) Integer pageNum,
            @RequestParam(value = "pageSize", required = true) Integer pageSize) {
        SwimmingRoom room = new SwimmingRoom();
        room.setRoomId(roomId);
        room.setRoomName(roomName);
        room.setPageNum(pageNum);
        room.setPageSize(pageSize);
        return swimmingRoomService.getAllRooms(room);
    }


    @ApiOperation("经营许可证图片上传接口")
    @PostMapping("/doUpload")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomId", value = "场所id", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "file", value = "上传图片", dataType = "multipartFiles", required = true)
    })
    public ApiResponse doUpload(
            @RequestParam(value = "file", required = true) MultipartFile multipartFiles,
            @RequestParam(value = "roomId", required = true) String roomId, HttpServletRequest request) {

        return swimmingRoomService.doUpload(multipartFiles, roomId, request);
    }
    @ApiOperation("获取省份对应城市")
    @PostMapping("/listArea")
    @ApiImplicitParams({@ApiImplicitParam(name = "province", value = "省份：如果没有传入province，则返回所有的省的信息.如果传入province，则返回这个省对应的市", dataType = "String", required = false),
            @ApiImplicitParam(name = "city", value = "市：如果传入了province以及city，则返回这个城市对应的区", dataType = "String", required = false)
    })
    public ApiResponse getCity(@RequestParam(value = "province", required = false) String province,
                               @RequestParam(value = "city", required = false) String city) {
        SwimmingRoom room = new SwimmingRoom();
        room.setProvince(province);
        room.setCity(city);
        return swimmingRoomService.getArea(room);
    }


}
